package com.mq.rabbitmq.deadletter;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.UUID;

/**
 * Created by xi on 2017/8/16.
 */
public class DealSend {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 不存在exchange会报错吗？
     * @param content
     */
    public void senToDeadLetter(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //记住一定要有routingkey,不然找到不绑定对列的名称
        //rabbitTemplate.setMandatory(true);
        rabbitTemplate.convertAndSend(DealLetterConfig.QUEUE_EXCHANGE , DealLetterConfig.QUEUE_DEAD_TEST, content, correlationId);
    }

}
